package com.cskaoyan.controller.adminController;

import com.cskaoyan.bean.MarketAdmin;
import com.cskaoyan.bean.common.BaseRespVo;
import com.cskaoyan.bean.common.CommonData;

import com.cskaoyan.service.admin.AdminService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author zjq
 * 管理员管理
 * url --> /admin/admin/*
 * @date 2022/11/19 16:45
 */
@RestController
@RequestMapping("/admin/admin")
public class AdminController {

    @Autowired
    AdminService adminService;
    /**
     * @author zjq
     * 分页查询管理员信息
     * url---->/admin/admin/list
     * @date 2022/11/19 16:53
     */
    @RequestMapping("/list")
    public BaseRespVo query(Integer page,Integer limit,String username,String sort,String desc){
        BaseRespVo baseRespVo = new BaseRespVo();
        CommonData commonData = adminService.fuzzyQuery(username, page, limit);
        return BaseRespVo.ok(commonData);
    }

    /**
     * @author zjq
     * @date 2022/11/21 14:21
     */
    @RequestMapping("/create")
    public BaseRespVo create(@RequestBody MarketAdmin admin){

        MarketAdmin marketAdmin = adminService.create(admin);
        BaseRespVo baseRespVo = new BaseRespVo();

        if(marketAdmin==null){
            baseRespVo.setErrmsg("用户名已存在");
            baseRespVo.setErrno(-1);
            return baseRespVo;
        }
        baseRespVo.setData("成功");
        baseRespVo.setErrno(0);
        baseRespVo.setData(marketAdmin);
        return baseRespVo;
    }

    /**
     * @author zjq
     * @date 2022/11/21 15:20
     */
    @RequestMapping("/delete")
    public BaseRespVo delete(@RequestBody MarketAdmin marketAdmin){
        int delete = adminService.delete(marketAdmin);
        return BaseRespVo.ok("删除成功");
    }

    // 修改会员管理信息
    @RequestMapping("/update")
    public BaseRespVo update(@RequestBody MarketAdmin admin) {
        MarketAdmin update = adminService.update(admin);
        return BaseRespVo.ok(update);
    }


}
